/*
 Copyright (c) 2014 ABB Group
 All rights reserved. This program and the accompanying materials
 are made available under the terms of the Eclipse Public License v1.0
 which accompanies this distribution, and is available at
 http://www.eclipse.org/legal/epl-v10.html
 
 Contributors:
    Christian Manteuffel (University of Groningen)
    K. Eric Harper (ABB Corporate Research)
*/

using System;
using EAFacade;
using EAFacade.Model;

namespace DecisionArchitect.Model
{
    public interface IConcern
    {
        string Name { get; }
        string ConcernGUID { get; }
        string DiagramGUID { get; set; }
    }


    public class Concern : IConcern
    {
        private const char Separator = ':';

        public Concern(string concernGUID)
        {
            IEAElement element = EAMain.Repository.GetElementByGUID(concernGUID);
            Name = element.Name;
            ConcernGUID = concernGUID;
        }

        public string Name { get; private set; }
        public string ConcernGUID { get; private set; }
        public string DiagramGUID { get; set; }

        public void DeserializeName(string value)
        {
            DiagramGUID = value.Split(Separator)[1];
        }

        public string SerializeName()
        {
            return String.Format(EATaggedValueKeys.IsConcernElement + Separator + "{0}", DiagramGUID);
        }

        public bool IsConcernElementTag(string name)
        {
            return name.StartsWith(EATaggedValueKeys.IsConcernElement);
        }
    }
}